//
//  ContentTableViewCell.m
//  UGoods
//
//  Created by dllo on 16/1/20.
//  Copyright © 2016年 蓝鸥科技.李贺. All rights reserved.
//

#import "ContentTableViewCell.h"
#import "FindModel.h"
#import <UIImageView+WebCache.h>
#import "BaseLabel.h"
#import "BaseView.h"
#import "ConstantsDefine.h"
@interface ContentTableViewCell ()

@property (nonatomic, retain) BaseLabel *contentLabel;
@property (nonatomic, retain) BaseView *backView;

@end

@implementation ContentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backView = [[BaseView alloc] init];
        [self.contentView addSubview:_backView];
        [_backView release];
        
        self.contentLabel = [[BaseLabel alloc] init];
        _contentLabel.textColor = [UIColor colorWithWhite:0.200 alpha:1.000];
        _contentLabel.font = [UIFont systemFontOfSize:13 * WIDTH];
        _contentLabel.numberOfLines = 0;
        [self.backView addSubview:_contentLabel];
        [_contentLabel release];
    }
    return self;
}

// 计算contentLabel高度
+ (CGFloat)heightWithText:(NSString *)text {
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(375 * WIDTH - 20 * WIDTH, 1000 * HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:13 * WIDTH]} context:nil];
    
    return rect.size.height;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat h = [[self class] heightWithText:_contentLabel.text];
    _backView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    _contentLabel.frame = CGRectMake(10 * WIDTH, 10 * HEIGHT, self.contentView.frame.size.width - 20 * WIDTH, h * HEIGHT);
}

- (void)setModel:(FindModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    _contentLabel.text = model.content;
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
